package com.example.controller;

import com.example.entity.dto.RespExpensesDTO;
import com.github.pagehelper.PageInfo;
import com.example.common.Result;
import com.example.entity.Employee;
import com.example.entity.Expenses;
import com.example.entity.dto.AddExpensesDTO;
import com.example.service.ExpensesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description TODO
 * @Author dingchunlin
 * @Date 2023/12/27 21:56
 * @Version 1.0.0
 */
@RequestMapping("/expenses")
@RestController
public class ExpensesController {

    @Autowired
    private ExpensesService expensesService;

    /**
     * 进行报销单的保存
     * @param addExpensesDTO
     * @return
     */
    @PostMapping("/add")
    public Result addExpenses(@RequestBody AddExpensesDTO addExpensesDTO){
        expensesService.addExpenses(addExpensesDTO);
        return Result.success();
    }

    @PutMapping("/update")
    public Result updateExpenses(@RequestBody AddExpensesDTO addExpensesDTO){
        expensesService.updateExpenses(addExpensesDTO);
        return Result.success();
    }

    /**
     * 根据用户id查询该用户的报销单
     * @param expenses
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/getExpensesById")
    public Result getExpensesById(Expenses expenses,
                                  @RequestParam(defaultValue = "1") Integer pageNum,
                                  @RequestParam(defaultValue = "10") Integer pageSize){
        PageInfo<Expenses> list = expensesService.getExpensesById(expenses,pageNum,pageSize);
        return Result.success(list);
    }

    /**
     * 根据报销单id查询详细信息
     * @param expensesId
     * @return
     */
    @GetMapping("/getExpensesDataById/{expensesId}")
    public Result getExpensesDataById(@PathVariable("expensesId") Integer expensesId){
        AddExpensesDTO dto = expensesService.getExpensesDataById(expensesId);
        return Result.success(dto);
    }


    @DeleteMapping("/delete/{id}")
    public Result deleteExpensesById(@PathVariable("id") Integer id){
        expensesService.deleteExpensesById(id);
        return Result.success();
    }

    @GetMapping("/getDetailExpenseData/{id}")
    public Result getDetailExpenseData(@PathVariable("id") Integer id){
        RespExpensesDTO res = expensesService.getDetailExpenseData(id);
        return Result.success(res);
    }


}
